package com._520it.wms.web.controller;

import com._520it.wms.domain.Supplier;
import com._520it.wms.query.QueryObject;
import com._520it.wms.service.ISupplierService;
import com._520it.wms.util.JSONResult;
import com._520it.wms.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by HASEE on 2017/11/14.
 */
@Controller
@RequestMapping("/supplier")
public class SupplierContorller {
    @Autowired
    private ISupplierService supplierService;

    @RequestMapping("/list")
    @RequiredPermission("供应商列表")
    public String list(Model model, QueryObject qo) {
        //int a = 1/0; 异常解析器
        model.addAttribute("pageResult", supplierService.query(qo));
        return "/supplier/list";
    }

    @RequestMapping("/input")
    @RequiredPermission("供应商编辑")
    public String input(Long id, Model model) {
        if (id != null) {
            Supplier supplier = supplierService.get(id);
            model.addAttribute("supplier", supplier);
        }
        return "/supplier/input";
    }

    @RequestMapping("delete")
    @RequiredPermission("供应商删除")
    @ResponseBody
    public JSONResult delete(Long id) {
        if (id != null) {
            supplierService.delete(id);
        }
        return new JSONResult();
    }

    @RequestMapping("/saveOrUpdate")
    @RequiredPermission("供应商新增/更新")
    @ResponseBody
    public JSONResult saveOrUpdate(Supplier supplier) {
        supplierService.saveOrUpdate(supplier);
        return new JSONResult();
    }


}
